;--------------------------------------------------------------------------------------------------
;Micro Operation System Project Copyright 2012
;Author : Ilya Churaev
;Started : 20 Apr 2012		Updated : 18 Nov 2012
;File Name : start.asm		Purpose : transfer of control to the kernel
;--------------------------------------------------------------------------------------------------

MBOOT_PAGE_ALIGN    equ 1<<0					; Load kernel and modules on a page boundary
MBOOT_MEM_INFO      equ 1<<1					; Provide your kernel with memory info
MBOOT_HEADER_MAGIC  equ 0x1BADB002				; Multiboot Magic value
; NOTE: We do not use MBOOT_AOUT_KLUDGE. It means that GRUB does not
; pass us a symbol table.
MBOOT_HEADER_FLAGS  equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
MBOOT_CHECKSUM      equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)


[BITS 32]										; All instructions should be 32-bit.

[GLOBAL mboot]									; Make 'mboot' accessible from C.
[EXTERN code]									; Start of the '.text' section.
[EXTERN bss]									; Start of the .bss section.
[EXTERN end]									; End of the last loadable section.

mboot:
	dd  MBOOT_HEADER_MAGIC						; GRUB will search for this value on each
												; 4-byte boundary in your kernel file
    dd  MBOOT_HEADER_FLAGS						; How GRUB should load your file / settings
    dd  MBOOT_CHECKSUM							; To ensure that the above values are correct
    
    dd  mboot									; Location of this descriptor
    dd  code									; Start of kernel '.text' (code) section.
    dd  bss										; End of kernel '.data' section.
    dd  end										; End of kernel.
    dd  _start									; Kernel entry point (initial EIP).

[GLOBAL _start]									; Kernel entry point.
[EXTERN Start0]								; This is the entry point of our C code

_start:
    ; Load multiboot information:
	push esp
	; Push the pointer to the Multiboot information structure.
    push ebx
	; Push the magic value.
    push eax
    ; Execute the kernel:
    cli											; Disable interrupts.
    call Start0								; call our main() function.
    jmp $										; Enter an infinite loop, to stop the processor
												; executing whatever rubbish is in the memory
												; after our kernel!
